import axios from 'axios'

const instance = axios.create({
  baseURL: import.meta.env.BASE_URL,
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json',
    'user-token': '12306070809_fa7ee89eeebceefce79131b20a9a3e00',
  },
})

// 请求拦截器
instance.interceptors.request.use(
  config => {
    return config
  },
  error => Promise.reject(error)
)

// 响应拦截器 - 增强错误处理
instance.interceptors.response.use(
  response => {
    if (response.status >= 200 && response.status < 300) {
      return response.data
    } else {
      return Promise.reject(response.data)
    }
  },
  error => {
    console.error('请求错误:', error)
    return Promise.reject(error)
  }
)

export default instance
